package com.yhsimon.realm.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhsimon.realm.member.constant.LevelCodeEnum;
import com.yhsimon.realm.member.entity.user.ExperienceEntity;
import com.yhsimon.realm.member.service.ExperienceService;
import com.yhsimon.realm.member.mapper.ExperienceMapper;
import com.yhsimon.realm.member.vo.user.UserExpVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 19819
 * @description 针对表【ums_experience(用户经验表)】的数据库操作Service实现
 * @createDate 2024-05-05 23:17:10
 */
@Service
public class ExperienceServiceImpl extends ServiceImpl<ExperienceMapper, ExperienceEntity>
        implements ExperienceService {

    @Autowired
    private ExperienceMapper experienceMapper;


    @Override
    public UserExpVo getUserExp(Long userId) {
        ExperienceEntity expEntity = experienceMapper.selectOne(new QueryWrapper<ExperienceEntity>().eq("user_id", userId));
        UserExpVo userExpVo = new UserExpVo();
        BeanUtils.copyProperties(expEntity, userExpVo);
        userExpVo.setLevelName(LevelCodeEnum.getLevelInfoByCode(expEntity.getLevelId().intValue()).getName());
        userExpVo.setThreshold(LevelCodeEnum.getLevelInfoByCode(expEntity.getLevelId().intValue()).getThreshold());
        return userExpVo;
    }
}




